﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace mirror
{
    public class cDesaturateEffect : cBaseRenderEffect
    {
        Effect effect;
        int mSaturationLevel;

        public cDesaturateEffect(mirror.Game1 zGame)
            : base(zGame.GraphicsDevice, zGame.spriteBatch)
        {

        }

        public override void Initialise(mirror.Game1 zGame)
        {
            effect = zGame.Content.Load<Effect>("Desaturate");
            mSaturationLevel = 255;
        }

        public override void Draw(GameTime gameTime,
                         RenderTarget2D resolveTarget,
                         RenderTarget2D renderTarget1,
                         RenderTarget2D renderTarget2)
        {
            mGraphicsDevice.SetRenderTarget(resolveTarget);
            
            Viewport viewport = mGraphicsDevice.Viewport;

            mSpriteBatch.Begin(SpriteSortMode.Immediate,
                  BlendState.Opaque);

            effect.CurrentTechnique.Passes[0].Apply();
        
            // Draw the quad. 
            // the color passed in has an alpha value - this controls the saturation level (from 0 to 255)
            mSpriteBatch.Draw(resolveTarget, new Rectangle(0, 0, viewport.Width, viewport.Height), new Color(255, 255, 255, mSaturationLevel));
            mSpriteBatch.End();

            mGraphicsDevice.SetRenderTarget(null);
        }
    }
}
